package com.lv.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

public class GetDataServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String city = request.getParameter("city");
        String whz = request.getParameter("whz");
        String gdId = request.getParameter("gdId");
        String zaxz = request.getParameter("zaxz");
        String zadl = request.getParameter("zadl");
        String zaReason = request.getParameter("zaReason");
        String desc1 = request.getParameter("desc1");
        String desc2 = request.getParameter("desc2");
        String desc3 = request.getParameter("desc3");
        String hapDate = request.getParameter("hapDate");
        String repDate = request.getParameter("repDate");
        String length = request.getParameter("length");
        String isOut = request.getParameter("isOut");
        String outReason = request.getParameter("outReason");
        String zcUse = request.getParameter("zcUse");
        String rrmark = request.getParameter("rrmark");
        String glCount = request.getParameter("glCount");
        String jthcount = request.getParameter("jthCount");
        int gl = Integer.parseInt(glCount);
        int jTH = Integer.parseInt(jthcount);

        ArrayList<String> glTypes = new ArrayList<>();
        ArrayList<String> jthTypes = new ArrayList<>();

        for (int i = 0; i < gl; i++) {
            String glType = request.getParameter("glType" + i);
            String glLength = request.getParameter("glLength" + i);
            glTypes.add("消耗光缆材料:"+glType+"芯"+glLength+"米");
        }

        for (int i = 0; i < jTH; i++) {
            String jthType = request.getParameter("jthType" + i);
            String jthCount = request.getParameter("jthCount" + i);
            jthTypes.add("消耗光缆材料:"+jthType+"芯"+jthCount+"米");
        }

        if (glTypes.size()>0){
//            RequestDispatcher requestDispatcher =request.getRequestDispatcher("success.jsp");
//            //调用forward()方法，转发请求
//            requestDispatcher.forward(request,response);
            response.sendRedirect("success.jsp");
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
